package ua.dp.md05;

import ua.dp.md05.dao.ProductDao;
import ua.dp.md05.dao.UserDao;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import java.util.List;

@Stateless
public class ProductTestdata {

	private static final String CONTENT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.";
	private static final String TITLE = "Product";

	private static final int QUANTITY = 5;

	@EJB
	private ProductDao productDao;

	@EJB
	private UserDao userDao;

	public void insert() {
		List<User> users = userDao.findAll();

        int j = 0;
		for (User user : users) {
			for (int i = 0; i < QUANTITY; i++) {
				Product product = new Product();
				product.setAuthor(user);
				product.setTitle(TITLE + j++);
                product.setBarcode(user.getUsername() + i);
				product.setContent(CONTENT);

				productDao.persist(product);
			}
		}
	}
}
